package com.wxl.common.room.entity;

import androidx.room.Entity;
import androidx.room.PrimaryKey;

import com.wxl.common.room.helper.DBHelper;
import com.wxl.common.util.DateUtils;
import com.wxl.common.util.ObservableUtil;

@Entity(tableName = "operate")
public class LogEntity extends OperateLogEntity {
    @PrimaryKey(autoGenerate = true)
    public int operateId;


    public static void addLog(String action, String code, String location, int total, double electric, double voltage, String stateCode,
                              int progress, int num, String errorCode, String remark) {
        LogEntity log = new LogEntity();
        log.time = DateUtils.Companion.getNowTime();
        log.action = action;
        log.electric = electric;
        log.errorCode = errorCode;
        log.instruct = code;
        log.location = location;
        log.num = num;
        log.progress = progress;
        log.stateCode = stateCode;
        log.remark = remark;
        log.voltage = voltage;
        log.total = total;
        DBHelper.Companion.insertOperateLog(new ObservableUtil.Companion.OnNextCallback<Boolean>() {
            @Override
            public void onNext(Boolean aBoolean) {

            }
        }, log);
    }

    public static void addLog(String code, String location, int total, double electric, double voltage, String stateCode,
                              int progress, int num, String errorCode, String remark) {
        addLog("", code, location, total, electric, voltage, stateCode, progress, num, errorCode, remark);
    }


    public static void addLog(String action, String location, int total) {
        addLog(action, "", location, total, 0, 0, "0", 0, 0, "", "");
    }

    public static void addLog(String action, String location, String remark) {
        addLog(action, "", location, 0, 0, 0, "0", 0, 0, "", remark);
    }

    @Override
    public String toString() {
        return "LogEntity{" +
                "operateId=" + operateId +
                ", time='" + time + '\'' +
                ", action='" + action + '\'' +
                ", instruct='" + instruct + '\'' +
                ", location='" + location + '\'' +
                ", total=" + total +
                ", electric=" + electric +
                ", voltage=" + voltage +
                ", stateCode='" + stateCode + '\'' +
                ", progress=" + progress +
                ", num=" + num +
                ", errorCode='" + errorCode + '\'' +
                ", remark='" + remark + '\'' +
                ", isUpload=" + isUpload +
                '}';
    }
}
